import React from "react";
import style from './style.module.scss';
import LeftArraw from "../../myConsultation/LeftArraw";
import { useSelector } from 'react-redux'
import { getTimeFormatText } from "../../../../utils/formatTime";
import { getHttp } from "../../../../api";
import { useRequest, useSetState } from "ahooks";

const Index: React.FC = () => {

  // 评论列表
  const { commentList } = useSelector((state: any) => state.doctor)
  // 医生id
  const {doctorId}=useSelector((state:any)=>state.doctor)
  console.log(doctorId);
  
  // 处理评论时间
  const timestampToTime=(timestamp)=>{
    timestamp = timestamp ? timestamp : null;
    const date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    const Y = date.getFullYear() + '-';
    const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    return Y + M + D + h + m + s;
  }


  const [infoCommentListParams, setinfoCommentListParams] = useSetState({
    doctorId: doctorId,
    page: 1,
    count:5
  });


  const getcommentlist = (params) =>
  getHttp("/health/user/inquiry/v1/findDoctorEvaluateList",params);
const { data: commentlist = [] } = useRequest(async () => {
  const resp = await getcommentlist(infoCommentListParams);
  return resp.result;
});





  return <div>
    <LeftArraw title="评论列表"></LeftArraw>
    <div className={style['comment-list']}>
      {
        commentlist.length > 0 && commentlist.map((v, i) => (
          <div key={i} className={style['comment_div']}>
              <p>
                <img src={v.headPic} alt="" className={style['comment_user_img']}/>
                <span>{v.nickName}</span>
                <span>{getTimeFormatText(new Date(timestampToTime(v.commentTime)))}</span>
              </p>
              <p>
                {v.content}
              </p>
            </div>
        ))
      }
    </div>
  </div>;
};

export default Index;
